<template>
	<el-dialog title="流程转交对话框" v-model="visible" :width="600" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<scTable ref="table" :data="stepList" height="auto" @row-click="singleElection"  paginationLayout="total, prev, pager, next" hideDo>
				<el-table-column label="步骤名称" prop="stepName" width="150">
					<template #default="scope">
						<el-radio class="radio" v-model="form.stepRunId" :label="scope.row.stepRunId" style="margin-right: 10px"></el-radio>{{scope.row.stepName}}
					</template>
				</el-table-column>
				<el-table-column label="当前操作人" prop="userName" width="100"></el-table-column>
				<el-table-column label="创建时间" prop="createTime" width="150"></el-table-column>
				<el-table-column label="接收人" width="200">
					<template #default="scope">
						<user-tag :account-ids="this.form.accountId" v-if="form.stepRunId==scope.row.stepRunId"></user-tag>
						<el-button v-if="form.stepRunId==scope.row.stepRunId" text type="primary" size="small" @click="setChangeUser(scope.row, scope.$index)">选择</el-button>
					</template>
				</el-table-column>
			</scTable>
			<msg-box-check-box v-model:msgType="form.msgType" code="bpm-change-user"></msg-box-check-box>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>
	<select-user-dialog ref="selectUserDialog" :is-not-show-btn="true" v-model:accountId="form.accountId" :mode="false"/>
</template>

<script>
import userTag from "@/views/module/userTag";
import selectUserDialog from "@/views/module/selectUserDialog";
import msgBoxCheckBox from "@/views/module/msgBoxCheckBox";
export default {
	components: {selectUserDialog,userTag,msgBoxCheckBox},
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			stepList:[],
			//表单数据
			form: {
				stepRunId: '',
				accountId: "",
				runId: "",
				msgType:""
			},
			//验证规则
			rules: {

			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		setChangeUser(row,index)
		{
			this.$nextTick(() => {
				this.$refs.selectUserDialog.selectOrgUser();
			})
		},
		singleElection(row)
		{
			this.form.stepRunId = row.stepRunId;
		},
		async getChangeBpmUserStep(runId){
			var res = await this.$API.bpm.bpmStepRun.getChangeBpmUserStep.get({runId:runId});
			if (res.code == 200) {
				this.stepList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//表单提交方法
		submit() {
			if(this.form.accountId=='')
			{
				this.$alert("请选择转交人员！", "提示", {type: 'error'})
				return false;
			}else {
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res = await this.$API.bpm.bpmStepRun.changeBpmStepRunUserByAdmin.post(this.form);
						this.isSaveing = false;
						if (res.code == 200) {
							this.$emit('success')
							this.visible = false;
							this.$message.success("操作成功")
						} else {
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				})
			}
		},
		setData(data) {
			this.form.runId = data.runId
			this.getChangeBpmUserStep(data.runId);
		},
	}
}
</script>

<style scoped>
:deep(.el-radio__label){
	display: none;
}
</style>
